//
//  HLNetInterface.m
//  ArtDog
//
//  Created by dllo on 16/10/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HLNetInterface.h"
#import "LocalJSONAnalytical.h"

@implementation HLNetInterface

- (instancetype)init
{
    NSDictionary *dic = [LocalJSONAnalytical JSONAnalyticalWithFileName:@"Network"];
    self = [self initWithDic:dic];
    if (self) {
        
    }
    return self;
}
@end

@implementation NSString (NetInterface)

@dynamic param;
@dynamic path;
@dynamic equalTo;
- (NSString *(^)(NSString *))path
{
    return ^(NSString * string) {
        NSString *appendString = [[self stringByAppendingString:@"/"]stringByAppendingString:string];
        return appendString;
    };
}

- (NSString *(^)(NSString *))param
{
    return ^(NSString * string) {
        NSString *appendString;
        if (![self containsString:@"?"] && ![self containsString:@"="]) {
            appendString = [[self stringByAppendingString:@"?"]stringByAppendingString:string];
        } else {
            appendString = [[self stringByAppendingString:@"&"]stringByAppendingString:string];
        }
        return appendString;
    };
}

- (NSString *(^)(id))equalTo
{
    return ^(id object) {
        NSString *appendString = [NSString stringWithFormat:@"%@=%@", self, object];
        return appendString;
    };
}


@end

@implementation NSDictionary (NetInterface)

@dynamic net_dict;

- (NSDictionary *(^)(id, id))net_dict
{
    return ^(id key, id value) {
        NSMutableDictionary *addDic = self.mutableCopy;
        [addDic setValue:[NSString stringWithFormat:@"%@", value] forKey:[NSString stringWithFormat:@"%@", key]];
        return addDic;
    };

}

@end



